@extends('layouts.admin')

@section('title', '角色管理')

@section('content')
<section class="Hui-article-box">
	<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 权限控制 <span class="c-gray en">&gt;</span> 角色管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
	<div class="Hui-article">
		<article class="cl pd-20">
			<div class="cl pd-5 bg-1 bk-gray"> <span class="l"><a class="btn btn-primary radius" href="javascript:;" onclick="admin_group_add('添加角色','addGroup','800')"><i class="Hui-iconfont">&#xe600;</i> 添加角色</a> </span> </div>
			<div class="mt-10">
			<table class="table table-border table-bordered table-hover table-bg">
				<thead>
					<tr>
						<th scope="col" colspan="6">角色管理</th>
					</tr>
					<tr class="text-c">
						<th width="40">ID</th>
						<th width="200">角色名</th>
						<th>权限列表</th>
						<th width="300">描述</th>
						<th width="300">操作</th>
					</tr>
				</thead>
				@foreach ($groups as $key)
				<tbody>
					<tr class="text-c">
						<td>{{ $key['id'] }}</td>
						<td>{{ $key['title'] }}</td>
						<td>{{ $key['rules'] }}</td>
						<td>{{ $key['msg'] }}</td>
						<td class="f-14">
							<a title="修改" href="javascript:;" onclick="admin_group_edit('角色编辑','editGroup',{{ $key['id'] }},'800')">修改</a> 
							<a title="删除" href="javascript:;" onclick="admin_group_del(this, 'delGroup',{{ $key['id'] }})" class="ml-5">删除</a>
						</td>
					</tr>
				</tbody>
				@endforeach
			</table>
			</div>
		</article>
	</div>
</section>
@endsection
@section('js')
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="{{ URL::asset('/admin/lib/My97DatePicker/4.8/WdatePicker.js') }}"></script>
<script type="text/javascript" src="{{ URL::asset('/admin/lib/datatables/1.10.0/jquery.dataTables.min.js') }}"></script>
<script type="text/javascript" src="{{ URL::asset('/admin/lib/laypage/1.2/laypage.js') }}"></script>
<script type="text/javascript">
/*
	参数解释：
	title	标题
	url		请求的url
	id		需要操作的数据id
	w		弹出层宽度（缺省调默认值）
	h		弹出层高度（缺省调默认值）
*/
/*管理员-权限-添加*/
function admin_group_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*管理员-权限-编辑*/
function admin_group_edit(title,url,id,w,h){
	let urls = url+'/'+id;
	layer_show(title,urls,w,h);
}

/*管理员-权限-删除*/
function admin_group_del(obj,url,id){
	layer.confirm('角色删除须谨慎，确认要删除吗？',function(index){
		$.post(url,{'_token':'{{csrf_token()}}','id' : id},function(call){
			if (call == 1) {
				$(obj).parents("tr").remove();
				layer.msg('删除成功!',{icon:1,time:1000});
			} else {
				layer.msg('删除失败!',{icon:1,time:1000});
			}
		})
		
	});
}
</script>
@endsection